/*
 * test_memstorage.c
 *
 *  Created on: Feb 15, 2011
 *      Author: thienlong
 */

#include "../src/mem_storage.h"
#include <stdio.h>
#include <pthread.h>
void *pthread_hanlder(void* arg) {
	mem_storage *storage = arg;
	unsigned int temp = 0;
	while (true) {
		int i = rand_r(&temp);
		i =  i % storage->block_size;
		void*data = mem_storage_alloc(storage, i, i % 2);
		printf("data: %p size: %d\n", data, i);
		fflush(stdout);
		sleep(1);
	}
}

int main(int argc, char **argv) {
	mem_storage *storage = mem_storage_new(0
#ifdef MEM_STORAGE_SUPPORT_THREAD_SAFE
			,true
#endif
			);
	pthread_t id = 0;
	pthread_create(&id, NULL, pthread_hanlder, storage);
	pthread_create(&id, NULL, pthread_hanlder, storage);
	while (true) {
		sleep(1000);
	}
}
